/**
* 订单管理 交易订单
*/
<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>项目管理</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 搜索筛选 -->
    <el-form :inline="true" :model="formInline" class="user-search">
      <el-form-item label="搜索：">
        <el-input size="small" v-model="formInline.projectName" placeholder="项目名称"></el-input>
      </el-form-item>
      <el-form-item label="">
        <el-button @click="handelAdd()">添加项目</el-button>
        <el-button @click="getdata()">搜索</el-button>
      </el-form-item>
    </el-form>
    <!--列表-->
    <el-table size="small" :data="listData" highlight-current-row v-loading="loading" border
              element-loading-text="拼命加载中" style="width: 100%;">
      <el-table-column sortable prop="id" label="项目id" width="120" show-overflow-tooltip>
      </el-table-column>
      <el-table-column sortable prop="projectName" label="项目名称" width="120" show-overflow-tooltip>
      </el-table-column>
      <el-table-column sortable prop="progressRate" label="进度" width="120" show-overflow-tooltip>
      </el-table-column>
      <el-table-column sortable prop="startTime" label="开始时间" width="140" show-overflow-tooltip>
      </el-table-column>
      <el-table-column sortable prop="projectLeaderName" label="负责任人" width="120"
                       show-overflow-tooltip></el-table-column>
      <el-table-column align="center" label="操作" min-width="150">
        <template slot-scope="scope">
          <el-button size="mini" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <Pagination v-bind:child-msg="pageparm" @callFather="callFather"></Pagination>
    <!-- 新增编辑 -->
    <el-dialog :title="title" :visible.sync="editFormVisible" width="80%" @click="closeDialog('editForm')">
      <el-form label-width="120px" :model="editForm" ref="editForm">
        <el-row>
          <el-col>
            <el-form-item v-show="false" label="id">
              <el-input size="small" v-model="editForm.id" auto-complete="off" placeholder="id"
                        disabled></el-input>
            </el-form-item>
            <el-form-item label="项目名称">
              <el-input size="small" v-model="editForm.projectName" auto-complete="off" placeholder="项目名称"
              ></el-input>
            </el-form-item>
            <el-form-item label="内容">
              <qiallQuillEditor @handleContext="handleContext" :context="editForm.context"/>
            </el-form-item>
            <el-form-item label="权限">
              <el-select v-model="editForm.permission" placeholder="请选择">
                <el-option label="部门内可见" value="部门内成员可见"></el-option>
                <el-option label="项目内成员可见" value="项目内成员可见">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="开始时间">
              <!--              <el-input size="small" v-model="editForm.startTime" auto-complete="off" placeholder="开始时间"-->
              <!--              ></el-input>-->
              <el-date-picker
                value-format="yyyy-MM-dd HH:mm:ss"
                v-model="editForm.startTime"
                type="datetime"
                placeholder="选择日期时间" style="width:30%">
              </el-date-picker>
            </el-form-item>
            <el-form-item label="结束时间">
              <!--              <el-input size="small" v-model="editForm.endTime" auto-complete="off" placeholder="结束时间"-->
              <!--              ></el-input>-->
              <el-date-picker
                v-model="editForm.endTime"
                type="datetime"
                value-format="yyyy-MM-dd HH:mm:ss"
                placeholder="选择日期时间" style="width:30%">
              </el-date-picker>
            </el-form-item>
            <el-form-item label="进度">
              <el-input style="width: 10%" size="small" v-model="editForm.progressRate" auto-complete="off"
                        placeholder="进度"
              ></el-input>
            </el-form-item>

            <el-form-item label="">
              <el-button v-show="editFormVisible_add" @click="submitForm()">添加项目</el-button>
              <el-button v-show="editFormVisible_mod" @click="submitForm()">修改项目</el-button>
            </el-form-item>
          </el-col>
        </el-row>

      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import {OrderList, OrderRefund, OrderDelete} from '../../api/payMG'
import Pagination from '../../components/Pagination'
import {getOrgByPage, getProjectByPage, saveOrUpdateProject} from "../../api/basisMG";
import {getStore} from "../../utils/util";
import qiallQuillEditor from "../component/qiall-quill-editor";

export default {
  data() {
    return {
      loading: false, //是显示加载
      editFormVisible: false, //控制编辑页面显示与隐藏
      editFormVisible_add: true,
      editFormVisible_mod: false,
      title: '预览',
      payType: [
        {key: '请选择', value: 0},
        {key: '现金', value: 1},
        {key: '支付宝', value: 2},
        {key: '微信', value: 3},
        {key: 'POS通', value: 4},
        {key: '闪付', value: 5},
        {key: 'POS通C扫B', value: 6},
        {key: '银联二维码', value: 8},
        {key: '会员余额支付', value: 9}
      ],
      payway: [
        {key: '请选择', value: 0},
        {key: '初始化', value: 1},
        {key: '已支付', value: 2},
        {key: '出货成功', value: 3},
        {key: '出货失败', value: 4},
        {key: '订单超时', value: 5},
        {key: '退款初始化', value: 11},
        {key: '退款进行中', value: 12},
        {key: '退款成功', value: 13},
        {key: '退款失败', value: 14},
        {key: '订单处理中', value: 10}
      ],
      editForm: {
        id: null,
        parentId: null,
        parentIds: '',
        projectName: '',
        context: '',
        permission: '',
        orgId: null,
        startTime: '',
        endTime: '',
        progressRate: '',

        projectMemberIds: '',
        creatorId: null,
        accessToken: getStore('accessToken')
      },
      formInline: {
        pageQuery: {
          startTime: null,
          endTime: null,
          pageSize: 10,
          pageNum: 1
        },
        projectName: '',
        accessToken: getStore('accessToken')

      },
      // 删除部门
      seletedata: {
        ids: '',
        token: localStorage.getItem('logintoken')
      },
      userparm: [], //搜索权限
      listData: [
        {
          id: 1,
          parentId: 1,
          parentProjectName: '',
          parentIds: '',
          parentProjectNames: '',
          projectName: '',
          context: '',
          permission: 1,
          startTime: '',
          endTime: '',
          progressRate: 1,
          projectLeaderId: 1,
          projectLeaderName: '',
          projectMemberIds: '',
          projectMemberNames: '',
          creatorId: 1,
          creatorName: '',
          orgId: 1,
          orgName: ''
        }
      ], //项目数据
      // 分页参数
      pageparm: {
        currentPage: 1,
        pageSize: 10,
        total: 10
      }
    }
  },
  // 注册组件
  components: {
    Pagination,
    qiallQuillEditor
  },
  /**
   * 数据发生改变
   */

  /**
   * 创建完毕
   */
  created() {
    this.getdata()
  },

  /**
   * 里面的方法只有被调用才会执行
   */
  methods: {
    // 获取公司列表
    getdata() {
      this.loading = true
      this.formInline.pageQuery.pageSize = this.pageparm.pageSize
      this.formInline.pageQuery.pageNum = this.pageparm.currentPage
      // 模拟数据开始
      let requestDataString = {
        requestData: JSON.stringify([this.formInline])
      }
      getProjectByPage(requestDataString).then(resp => {
        if (resp.body.responseData.status === 0) {
          this.loading = false
          this.listData = resp.body.responseData.body.dataList
          this.pageparm.total = resp.body.responseData.body.total
        }
      })
      this.loading = false
      // 模拟数据结束

      /***
       * 调用接口，注释上面模拟数据 取消下面注释
       */

      // OrderList(parameter)
      //   .then(res => {
      //     this.loading = false
      //     if (res.success == false) {
      //       this.$message({
      //         type: 'info',
      //         message: res.msg
      //       })
      //     } else {
      //       this.listData = res.data
      //       // 分页赋值
      //       this.pageparm.currentPage = this.formInline.page
      //       this.pageparm.pageSize = this.formInline.limit
      //       this.pageparm.total = res.count
      //     }
      //   })
      //   .catch(err => {
      //     this.loading = false
      //     this.$message.error('菜单加载失败，请稍后再试！')
      //   })
    },
    // 分页插件事件

    handleContext(val) {
      this.editForm.context = val
    },
    callFather(parm) {
      this.formInline.page = parm.currentPage
      this.formInline.limit = parm.pageSize
      this.getdata(this.formInline)
    },
    // 搜索事件
    search() {
      this.getdata(this.formInline)
    },
    //显示编辑界面
    handleEdit: function (index, row) {
      this.editFormVisible = true
      this.editFormVisible_add = false
      this.editFormVisible_mod = true
      this.editForm.id = row.id
      this.editForm.parentId = row.parentId
      this.editForm.parentIds = row.parentIds
      this.editForm.projectName = row.projectName
      this.editForm.context = row.context
      this.editForm.permission = row.permission
      this.editForm.orgId = row.orgId
      this.editForm.startTime = row.startTime
      this.editForm.endTime = row.endTime
      this.editForm.progressRate = row.progressRate
    }
    ,
    //显示编辑界面
    handelAdd: function () {
      this.editFormVisible = true
      this.editFormVisible_add = true
      this.editFormVisible_mod = false
    }
    ,
    // 编辑、增加页面保存方法
    submitForm() {
      if (this.editFormVisible_add == true) {
        this.editForm.id = null;
      }
      let requestDataString = {
        requestData: JSON.stringify([this.editForm])
      }
      saveOrUpdateProject(requestDataString)
        .then(res => {
          this.editFormVisible = false
          this.loading = false
          if (res.body.responseData.status === 0) {
            this.getdata(this.formInline)
            this.$message({
              type: 'success',
              message: '新增成功'
            })
          } else {
            this.$message({
              type: 'info',
              message: '新增失败'
            })
          }
        })
        .catch(err => {
          this.editFormVisible = false
          this.loading = false
          this.$message.error('支付配置信息保存失败，请稍后再试！')
        })
    }
    ,


    // 关闭编辑、增加弹出框
    closeDialog(formName) {
      this.editFormVisible = false
      this.$refs[formName].resetFields()
    }
  }

}
</script>

<style scoped>
.user-search {
  margin-top: 20px;
}

.userRole {
  width: 100%;
}

</style>




